<template>
    <div id="major">
        <table>
            <tr>
                <td>编号:</td>
                <td>
                    <input class="form-control" v-model="major.id" readonly>
                </td>
            </tr>
            <tr>
                <td>专业名称:</td>
                <td>
                    <input class="form-control" v-model="major.text" placeholder="请输入专业名称">
                </td>
            </tr>
            <tr>
                <td>描述:</td>
                <td>
                    <textarea class="form-control" v-model="major.desc">
                    </textarea>
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    <button class="btn btn-success" @click="add">修改</button>
                    <button class="btn btn-warning">关闭</button>
                </td>
            </tr>
        </table>

    </div>
</template>
<script>
export default {
    props:["id"],
    data() {
        return {
            major:{}
        }
    },
    mounted() {
        //获取当前文件中最大的id
        console.log(this.id);
        this.$http.get("majors/"+this.id).then(rs=>{
            this.major = rs.data;
        })
    },
    methods: {
        add(){
            console.log(this.major);
            this.$http.put(`majors/${this.id}`,this.major).then(rs=>{
                if(rs.status===200){
                    this.$layer.msg('修改专业成功...')
                    this.$parent.initData();
                    this.$layer.closeAll();
                }
            })
        }
    },
}
</script>
<style lang="less" scoped>
    #major{
        table{
            width: 380px;
            margin: 0px auto;
            padding: 10px;
            height: 200px;
        }
        tr{
            text-align: center;
        }
        tr button{
            margin: 0 20px;
        }
    }
</style>